package com.gdsdxy.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gdsdxy.dto.AlbumFromDTO;
import com.gdsdxy.dto.ResultVo;
import com.gdsdxy.entity.Album;
import com.gdsdxy.mapper.AlbumMapper;
import com.gdsdxy.service.IAlbumService;
import com.gdsdxy.utils.UserHolder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AlbumServiceImpl extends ServiceImpl<AlbumMapper, Album> implements IAlbumService {


    @Override
    public ResultVo saveAlbum(AlbumFromDTO albumFromDTO) {
        // 获取用户id
        Long id = UserHolder.getUser().getId();
        //获取图片名称
        String name = albumFromDTO.getName();
        // 判断相册是否为空
        if (StrUtil.isBlank(name)) {
            return ResultVo.fail("不能为空");
        }

        Album album = BeanUtil.copyProperties(albumFromDTO, Album.class);
        boolean result = save(album);
        return result ? ResultVo.ok("添加成功") : ResultVo.fail("添加失败");
    }

    @Override
    public ResultVo deleteAlbum(Long id) {
        boolean result = removeById(id);
        return result ? ResultVo.ok("删除成功") : ResultVo.fail("删除失败");
    }

    @Override
    public ResultVo queryAlbum(Long id) {
        Album result = getById(id);
        return result != null ? ResultVo.ok(result) : ResultVo.fail("相册不存在");

    }
}
